package com.aispeech.asr.apis.ssc.config;

import java.util.HashMap;
import java.util.Map;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter;

import com.aispeech.asr.apis.ssc.websocket.handler.SdWsHandler;

@Configuration
public class WebSocketConfig {
	
	@Bean
    public SdWsHandler getSdWsHandler() {
        return new SdWsHandler();
    }
	
    @Bean
    public HandlerMapping handlerMapping() {
        Map<String, WebSocketHandler> webSocketHandlerMap = new HashMap<>();
        
        webSocketHandlerMap.put("/ssc-api/v1/sd/online", getSdWsHandler());

        int order = -1;

        return new SimpleUrlHandlerMapping(webSocketHandlerMap, order);
    }

    @Bean
    public WebSocketHandlerAdapter webSocketHandlerAdapter() {
        return new WebSocketHandlerAdapter();
    }
}
